package pumpkin.ast;

import pumpkin.evt.Environment;
import pumpkin.word.SymbolTxt;
import pumpkin.word.Token;
import pumpkin.word.TokenSource;
import pumpkin.word.TokenType;

/**
 * * F->(E)|id
 * 
 * @author jiang
 *
 */
public class Fexpr implements Node {
	Expr expr =null;
	Id id=null;
	private boolean isId = false;

	@Override
	public void build(TokenSource tokenSource) {
		Token tk = tokenSource.next();
		if (tk.getType() == TokenType.SYMBOL && SymbolTxt.LSquar.getSymbol().equals(tk.getText())) {
			isId = false;
			expr= new Expr();
			expr.build(tokenSource);
			Token tkk = tokenSource.next();
		}else {
			isId = true;
			id=new Id();
			id.build(tk);
		}
	}

	@Override
	public Object excute(Environment env) {
		if(isId) {
			return id.excute(env);
		}
		return expr.excute(env);
	}
}